<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>load04</title>
<!-- 4.使用window.onload，完美解决此问题 -->
<script type="text/javascript">
	window.onload = function () {
		var btn = document.getElementById("btnId");
		btn.onclick = function () {
			alert("hello");
		};
	};
</script>
</head>
<body>
	<button id="btnId">SayHello</button>
</body>
</html>